<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="lineBox">
        <el-button size="mini" class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit"
          @click="$router.push('/consulting/addconsulting')">
          新增
        </el-button>
      </div>
    </div>

    <div class="myTable">
      <el-table :key="tableKey" v-loading="listLoading" :data="list" fit size="mini" highlight-current-row
        style="width: 100%;">
        <el-table-column label="ID" prop="id" align="center" min-width="50" />
        <el-table-column label="标题" prop="title" align="center" min-width="200" />
        <el-table-column label="发布时间" prop="create_time" align="center" min-width="200" />
        <el-table-column label="标签" prop="label" align="center" min-width="100" />
        <el-table-column label="用户阅读数" prop="reading_volume" align="center" min-width="100" />
        <el-table-column label="操作" align="center" min-width="160" class-name="small-padding fixed-width">
          <template slot-scope="{row,$index}">
            <el-button icon="el-icon-edit" type="primary" size="mini"
              @click="$router.push({ path: '/consulting/eidconsulting?id='+row.id})">
              编辑
            </el-button>
            <el-button type="primary" icon="el-icon-delete" size="mini" @click="handleDelete(row,$index)">
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination size="mini" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
        layout="total, sizes, prev, pager, next, jumper" @pagination="consultingList" />
    </div>
  </div>
</template>

<script>
import { getconsultingList, deleteConsultingById } from '@/api/consulting'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
export default {

  components: { Pagination },
  filters: {
    statusFilter (status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data () {
    return {

      inputDisabled: false,
      tableKey: 0,
      list: [],
      total: 100,
      listLoading: false,
      listQuery: {
        pageNumber: 1,
        pageSize: 10,

        limit: 10,
      },
      showReviewer: false,

    }
  },
  created () {
    this.consultingList()
  },
  methods: {
    // 数据列表
    async consultingList () {
      this.listLoading = true
      const response = await getconsultingList(this.listQuery)
      if (response.code == 200) {
        console.log(response)
        this.list = response.data.resultList
        this.total = response.totalCount
        // this.type = response.type
        //   // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 1.5 * 1000)
      }
    },



    // 删除指标
    async handleDelete (row, index) {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const data = { 'id': row.id }

        const response = await deleteConsultingById(data)
        if (response.code == 200) {
          this.$notify({
            title: '成功',
            message: response.message,
            type: 'success',
            duration: 2000
          })
          this.list.splice(index, 1)
        } else {
          this.$notify({
            title: '失败',
            message: response.message,
            type: 'error',
            duration: 2000
          })
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
